package org.baojie.raft.node;

import java.io.Serializable;

// 节点在群组中唯一确定的名称
public class NodeName implements Serializable {

    private static final long serialVersionUID = -5342192371619736616L;
    // 节点在群组中的名称
    private final String name;

    private final NodeAddress address;

    public NodeName(String name, NodeAddress address) {
        this.name = name;
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public NodeAddress getAddress() {
        return address;
    }

    @Override
    public boolean equals(Object obj) {
        if (null == obj) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (obj instanceof NodeName) {
            NodeName tmp = (NodeName) obj;
            if (!this.name.equals(tmp.name)) {
                return false;
            }
            if (!this.address.equals(tmp.address)) {
                return false;
            }
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + name.hashCode();
        result = 31 * result + address.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "NodeName{" +
                "name='" + name + '\'' +
                ", address='" + address + '\'' +
                '}';
    }
}
